home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / mui / MadMatrixsrc.lha / MadMatrix.src / alloctab.c next >
Encoding:
C/C++ Source or Header  |  2000-03-18  |  871 b   |  57 lines

  1. #include <stdlib.h>
  2.  
  3. /*#define DEBUG*/
  4.  
  5. void **AllocTab(size_t taille,int nblignes, int nbcolonnes)
  6. {
  7.   void **nouveau;
  8.   int i,j;
  9.  
  10.   nouveau= ( void **) calloc(nblignes,sizeof(void *));
  11.  
  12. #ifdef DEBUG
  13.   printf("Allocation de %p !\n",nouveau);
  14. #endif
  15.  
  16.   if ( nouveau == NULL )
  17.     return(NULL);
  18.  
  19.   for ( i=0; i< nblignes ; i ++ )
  20.     if ( NULL == (nouveau[i] = calloc(nbcolonnes,taille) ) )
  21.       break;
  22. #ifdef DEBUG
  23.     else
  24.       printf("Allocation de %p\n",nouveau[i]);
  25. #endif
  26.  
  27.   if ( i < nblignes )
  28.   {
  29.     for ( j=0; j < i ; j++ )
  30.       free(nouveau[j]);
  31.  
  32.     free(nouveau);
  33.     return(NULL);
  34.   }
  35.   return(nouveau);
  36. }
  37.  
  38. void FreeTab(void **tab, int nblignes)
  39. {
  40.   int j;
  41.  
  42.   for ( j=0; j < nblignes ; j++ )
  43.   {
  44. #ifdef DEBUG
  45.     printf("Liberation de %p\n",tab[j]);
  46. #endif
  47.     free(tab[j]);
  48.   }
  49.  
  50. #ifdef DEBUG
  51.   printf("Liberation de %p !\n",tab);
  52. #endif
  53.   free(tab);
  54. }
  55.  
  56.  
  57.